<template>
	<view>
		<view style="width: 95%;margin: auto;">
			<uni-search-bar v-model="stuNameOrPhone" @cancel="cancel" @confirm="search" @input="input" ></uni-search-bar>
		</view>
		<view style="width: 95%;margin: auto;">
			<uni-list>
				<uni-list-item v-for="(item,index) in stuData" 
								:key="index" 
								:title="item.studentName" 
								:rightText="item.studentPhone"
								link :to="'./stuDetails?studentId='+item.studentId">
				</uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	import {formalStuByUserId} from "../../../api/student.js";
	export default {
		data() {
			return {
				stuNameOrPhone:null,
				userId : 2,
				stuData:[]
			}
		},
		onLoad() {
			this.getStuData();
		},
		methods: {
			search(){
				this.getStuData();
			},
			cancel(){
				this.stuNameOrPhone = null
				this.getStuData()
			},
			getStuData(){			
				formalStuByUserId(this.userId,this.stuNameOrPhone).then(res => {
					this.stuData = res.data
					console.log(this.stuData)
				})
			}
		}
	}
</script>

<style>
</style>
